package com.sina.weibo;

import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Handler;
import android.widget.ProgressBar;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import sudroid.DataStructureUtil;
import sudroid.android.FileUtil;

final class LocationHelper
{
  private EditActivity activity;
  private String defaultDraftPath;
  private LocationHolder holder;
  private boolean isLocated;
  private LocationListener mLocationListener;
  private LocationManager mLocationManager;
  private boolean startFetching;
  private int timeout;
  private Handler uiHandler;

  LocationHelper(EditActivity paramEditActivity)
  {
    this.activity = paramEditActivity;
    LocationManager localLocationManager = (LocationManager)paramEditActivity.getSystemService("location");
    this.mLocationManager = localLocationManager;
    Handler localHandler = new Handler();
    this.uiHandler = localHandler;
    this.timeout = 60;
    String str1 = String.valueOf(paramEditActivity.getFilesDir().getAbsolutePath());
    String str2 = str1 + "/draft/location.dat";
    this.defaultDraftPath = str2;
  }

  private LocationListener getLocationListener()
  {
    if (this.mLocationListener == null)
    {
      LocationHelper.1 local1 = new LocationHelper.1(this);
      this.mLocationListener = local1;
    }
    return this.mLocationListener;
  }

  private void requestProviders()
  {
    Utils.logd("\trequestProviders()");
    List localList = this.mLocationManager.getProviders(1);
    int i = 0;
    if (DataStructureUtil.isEmptyOrNull(localList))
      this.activity.showDialog(1000);
    while (true)
    {
      return;
      if (localList.contains("gps"))
      {
        LocationManager localLocationManager1 = this.mLocationManager;
        LocationListener localLocationListener1 = getLocationListener();
        localLocationManager1.requestLocationUpdates("gps", 0L, 0.0F, localLocationListener1);
        i = 1;
      }
      if (localList.contains("network"))
      {
        LocationManager localLocationManager2 = this.mLocationManager;
        LocationListener localLocationListener2 = getLocationListener();
        String str = "network";
        localLocationManager2.requestLocationUpdates(str, 0L, 0.0F, localLocationListener2);
        i = 1;
      }
      if (i == 0)
        continue;
      this.activity.pgLoadingLocation.setVisibility(0);
      this.startFetching = 1;
      if (this.timeout <= 0)
        continue;
      Handler localHandler = this.uiHandler;
      LocationHelper.2 local2 = new LocationHelper.2(this);
      long l = this.timeout * 1000;
      boolean bool = localHandler.postDelayed(local2, l);
    }
  }

  void closeAll()
  {
    if (this.mLocationListener != null)
    {
      LocationManager localLocationManager = this.mLocationManager;
      LocationListener localLocationListener = getLocationListener();
      localLocationManager.removeUpdates(localLocationListener);
      this.mLocationListener = null;
    }
  }

  boolean deleteDraft()
  {
    Utils.logd("删除地理位置信息缓存");
    return FileUtil.deleteDependon(this.defaultDraftPath);
  }

  void dispose()
  {
    closeAll();
    this.isLocated = 0;
    this.startFetching = 0;
    this.holder = null;
  }

  boolean doesDraftExist()
  {
    return FileUtil.doesExisted(this.defaultDraftPath);
  }

  boolean equalDraft()
  {
    try
    {
      if (doesDraftExist())
      {
        LocationHolder localLocationHolder1 = (LocationHolder)FileUtil.loadObject(this.defaultDraftPath);
        LocationHolder localLocationHolder2 = this.holder;
        boolean bool1 = localLocationHolder1.equals(localLocationHolder2);
        bool2 = bool1;
        return bool2;
      }
    }
    catch (Exception localException)
    {
      while (true)
      {
        Utils.loge(localException);
        boolean bool2 = false;
      }
    }
  }

  LocationHolder getLocationHolder()
  {
    if (!isLocatedSucess())
      throw new IllegalStateException("");
    return this.holder;
  }

  boolean isFetching()
  {
    return this.startFetching;
  }

  boolean isLocatedSucess()
  {
    if ((this.holder != null) && (this.holder.isUseful()));
    for (int i = 1; ; i = 0)
      return i;
  }

  boolean isNeverLocated()
  {
    if ((!this.startFetching) && (!this.isLocated));
    for (int i = 1; ; i = 0)
      return i;
  }

  void loadDraft()
  {
    try
    {
      LocationHolder localLocationHolder = (LocationHolder)FileUtil.loadObject(this.defaultDraftPath);
      this.holder = localLocationHolder;
      this.activity.onLocatedSuccess();
      this.isLocated = 1;
      Utils.logd("\t 读取地理信息缓存成功");
      return;
    }
    catch (Exception localException)
    {
      while (true)
        Utils.loge(localException);
    }
  }

  void openAllProviders()
  {
    if ((this.startFetching) || (this.isLocated));
    while (true)
    {
      return;
      requestProviders();
    }
  }

  boolean saveDraft()
  {
    try
    {
      boolean bool = FileUtil.deleteDependon(this.defaultDraftPath);
      FileUtil.makesureFileExist(this.defaultDraftPath);
      LocationHolder localLocationHolder = this.holder;
      String str = this.defaultDraftPath;
      FileOutputStream localFileOutputStream = new FileOutputStream(str);
      FileUtil.saveObject(localLocationHolder, localFileOutputStream);
      Utils.logd("\t 存储地理信息缓存成功");
      i = 1;
      return i;
    }
    catch (Exception localException)
    {
      while (true)
      {
        Utils.loge(localException);
        int i = 0;
      }
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     com.sina.weibo.LocationHelper
 * JD-Core Version:    0.6.0
 */